#include <QtSql>
#include <QCoreApplication>
#include <QDebug>

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("test.db");

    if (!db.open()) {
        qDebug() << "Cannot open database:" << db.lastError();
        return -1;
    }

    QSqlQuery query;
    query.exec("create table student (id int primary key, name varchar(30))");
    query.exec("insert into student values(1, 'Tom')");
    query.exec("insert into student values(2, 'Jerry')");

    query.exec("select * from student");
    while (query.next()) {
        qDebug() << query.value(0).toInt() << query.value(1).toString();
    }

    return 0;
}
